#pragma once
#include "game.h"
#include "utils.h"
#include <fstream>
#include <mutex>
#include <string>
#include <unordered_map>

#define ITEM_CACHE_FILE "C:\\wow\\classic_wlk\\data\\item-cache.dat"

struct CacheData {
  uint32 type_index;
  std::string type;
  uint32 subtype_index;
  std::string subtype;
};

struct ItemCache {
  struct CacheData get_item_type_info(uint32 item_id);
  // --- Constructors ---
  ItemCache(std::shared_ptr<Game> game,
            const std::string &cache_file = ITEM_CACHE_FILE);
  ItemCache(ItemCache &&) = delete;
  ItemCache(const ItemCache &) = delete;
  ItemCache &operator=(ItemCache &&) = delete;
  ItemCache &operator=(const ItemCache &) = delete;
  ~ItemCache();

  void load_from_disk();
  void save_to_disk();

private:
  std::shared_ptr<Game> game_;
  std::unordered_map<int, struct CacheData> memory_cache_;
  std::string cache_file_;
  std::mutex mutex_;

private:
  struct CacheData fetch_from_game(uint32 item_id);
};
